package tcu.iot.gasmanage.common.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tcu.iot.gasmanage.entity.equipment.EquipmentData;
import tcu.iot.gasmanage.mapper.EquipmentMapper;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

public class GetActionDataUtils {

    //获得没有信号强度设备的所有数据，只获取第一条；
    public static List<EquipmentData> GetActionDataLimit1(List<String> tablelist) {
        List<EquipmentData> list = new ArrayList<>();

        for (String s : tablelist) {
            //将获取到的数据转换为实体类，并且加入list
            EquipmentData equipmentData = JSONUtils.parseEquipmentDataLimit1(s, "select * from electory." + s + " order by ts desc LIMIT 1");
            list.add(equipmentData);
        }

        return list;
    }

    //获取包含信号强度设备的所有数据
    public static List<EquipmentData> WithSignalGetActionDataLimit1(List<String> signalTableList) {
        List<EquipmentData> list = new ArrayList<>();

        for (String s : signalTableList) {
            EquipmentData equipmentData = JSONUtils.WithSignalparseEquipmentDataLimit1(s, "select * from electory." + s + " order by ts desc LIMIT 1;");
            list.add(equipmentData);
        }

        return list;
    }

    //将包含信号强度和不包含信号强度的List合并返回
    public static List<EquipmentData> AllActionList(List<String> list, List<String> signalList) {
        //在这个list中定义了所有设备的设备ID，这样就可以对应物联网数据库中的所有表
//        List<String> list = equipmentMapper.GetEquipmentWithoutSignal();
//        System.out.println(list);
//        List<String> list = new ArrayList<>();
//        list.add("bd16265282985790001");
//        list.add("bd16265285926210005");
//        list.add("bd16265286316690006");
//        list.add("bd16265285067860003");
//        list.add("bd16115918765499318");
//        list.add("bd16265285498460004");
//        list.add("bd16265284510910002");
//        list.add("bd16115915009363114");
//        list.add("bd16115919681023314");
//        list.add("bd16115920421912920");

//        List<String> signalList = new ArrayList<>();
//        signalList.add("bd1631436742312");
//        List<String> signalList = equipmentMapper.GetEquipmentWithSignal();

        //将包含信号强度字段的设备list，与不包含信号强度字段的设备list，合并成为一个list
        List<EquipmentData> EquipmentDatalist = new ArrayList<>();
        EquipmentDatalist.addAll(GetActionDataLimit1(list));
        EquipmentDatalist.addAll(WithSignalGetActionDataLimit1(signalList));

        return EquipmentDatalist;
    }
}
